package com.test.turntable.widgets;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

public class TrunTableView extends View {

	Paint mPaint;
	boolean mIsDraw = false;
	float mRadius = 150;
	int mLineCount = 4;

	public TrunTableView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	public TrunTableView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public TrunTableView(Context context) {
		super(context);
		init();
	}

	private void init() {
		mPaint = new Paint();
		mPaint.setColor(Color.BLACK);
		mPaint.setStyle(Style.STROKE);
		mPaint.setAntiAlias(true);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.translate(getWidth() / 2, getHeight() / 2);

		canvas.drawCircle(0, 0, mRadius, mPaint);

		canvas.rotate(180 / mLineCount / 2);
		canvas.save();

		for (int i = 0; i < mLineCount; i++) {
			canvas.drawLine(-mRadius, 0, mRadius, 0, mPaint);
			canvas.rotate(180 / mLineCount);
		}

		canvas.restore();
		mPaint.setStyle(Style.FILL);
		int Colors[] = { Color.RED, Color.YELLOW, Color.GRAY, Color.BLUE, Color.GREEN, Color.CYAN, Color.MAGENTA, Color.DKGRAY };
		RectF oval = new RectF(-mRadius, -mRadius, mRadius, mRadius);
		for (int i = 0; i < Colors.length; i++) {
			mPaint.setColor(Colors[i]);
			canvas.drawArc(oval, i * 180 / mLineCount, 180 / mLineCount, true, mPaint);
		}
	}
}
